package com.hyd.action;

import java.util.List;
import com.base.dialect.PaginationSupport;
import com.base.dao.model.Ret;
import com.base.dao.model.Grid;
import com.base.util.StringUtil;
import com.hyd.daoEx.model.EvidenceEx;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.commons.lang.StringUtils;
import com.base.util.JSONUtils;
import com.base.web.annotation.LoginFilter;
import org.springframework.beans.factory.annotation.Autowired;
import com.base.action.CoreController;
import com.hyd.dao.model.Evidence;
import com.hyd.dao.model.EvidenceExample;
import com.hyd.service.EvidenceService;

/**
@author sun
*/
@RequestMapping("evidence")
@Controller
@LoginFilter
public class EvidenceController extends CoreController{

    @Autowired
    private EvidenceService evidenceService;

    @RequestMapping("/list")
	@ResponseBody
    public String list(Integer page, Integer rows, String log_id, String name){
    	PaginationSupport.byPage(page, rows);
    	EvidenceExample example = new EvidenceExample();
		EvidenceExample.Criteria criterion = example.createCriteria();
		if(StringUtil.isNotBlank(log_id)){
			criterion.andLogIdLike("%"+log_id+"%");
		}
		if(StringUtil.isNotBlank(name)){
			criterion.andNameLike("%"+name+"%");
		}

    	List<Evidence> list = evidenceService.selectByExample(example);
      	return page(list);
    }

    @RequestMapping("/save")
	@ResponseBody
    public String save(Evidence evidence){
    	if (evidence.getId() == null){
    		evidenceService.insert(evidence);
    	}else{
    		evidenceService.updateByPrimaryKeySelective(evidence);
    	}
       	return ok();
    }

    @RequestMapping("/findById")
	@ResponseBody
    public String find(Integer id){
    	Evidence evidence = evidenceService.selectByPrimaryKey(id);
       	return ok(evidence);
    }

    @RequestMapping("/del")
	@ResponseBody
    public String del(String id){
    	String[] ids = id.split(",");
    	for (String str : ids){
    		evidenceService.deleteByPrimaryKey(Integer.parseInt(str));
    	}
       	return ok();
    }

	@RequestMapping("/count")
	@ResponseBody
	public String count(){
		EvidenceExample example = new EvidenceExample();
		int count = evidenceService.countByExample(example);
		return ok(count);
	}
}